<template>
  <div id="app">
    <el-select v-model="bigArea" @change="onChange" clearable placeholder="请选择">
      <el-option v-for="item in serveList" :key="item.service" :label="item.service" :value="item.service">
      </el-option>
    </el-select>
    <el-select v-model="out" clearable @change="getAllCanIn" placeholder="请选择">
      <el-option v-for="item in labelList" :key="item" :label="item" :value="item">
      </el-option>
    </el-select>
    <el-row>
      <el-col :span="4" v-for="(item, i) in ableInList" :key="'canIn' + i"> {{ item }} </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'App',
  components: {

  },
  data() {
    return {
      list: {},
      bigArea: '',
      serveList: [],
      labelList: [], // 所有转出去信息
      ableInList: [],
      array: [],
      out: ''
    }
  },
  created() {
    this.getData()
    this.getServices()
  },
  methods: {
    onChange(bigArea) {
      this.out = ''
      for (let index = 0; index < this.serveList.length; index++) {
        const element = this.serveList[index];
        if (bigArea == element.service) {
          this.labelList = element.list
        }
      }
    },
    getAllCanIn(In) {
      this.ableInList = []
      for (let index = 0; index < this.array.length; index++) {
        let flag = false
        const element = this.array[index];
        for (let ind = 0; ind < element.in.length; ind++) {
          const ele = element.in[ind];
          if (In == ele) {
            flag = true
          }
        }
        if (flag) {
          this.ableInList.push(element.out)
          flag = false
        }
      }
    },
    getData() {
      axios.get('https://xyq.163.com/2011/zhuanyi/js/travel_list.js')
        .then(response => {
          this.array = []
          this.list = JSON.parse(unescape(response.data.replace(/\\u/g, '%u')).split('=')[1])
          let keys = Object.keys(this.list)
          this.labelList = keys
          for (let index = 0; index < keys.length; index++) {
            const key = keys[index];
            this.array.push({
              out: key,
              in: this.list[key]
            })
          }
        })
    },
    getServices() {
      axios.get('https://xyq.163.com/2011/zhuanyi/js/server_list.js')
        .then(response => {
          const list = JSON.parse(unescape(response.data.replace(/\\u/g, '%u')).split('=')[1])
          let keys = Object.keys(list)
          let serveList = new Set()
          for (let index = 0; index < keys.length; index++) {
            const key = keys[index];
            serveList.add(list[key])
          }
          let newList = [...serveList]
          let districtServer = []
          for (let index = 0; index < newList.length; index++) {
            const element = newList[index]
            let signleAre = {
              service: element,
              list: []
            }
            for (let ind = 0; ind < keys.length; ind++) {
              const ele = keys[ind];
              if (element == list[ele]) {
                signleAre.list.push(ele)
              }
            }
            districtServer.push(signleAre)
          }
          this.serveList = districtServer
        })
    }


  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
